//
//  starView.m
//  timemovie
//
//  Created by Yiqiao on 15/7/21.
//  Copyright (c) 2015年 Yiqiao. All rights reserved.
//

#import "starView.h"

@implementation starView
- (void)setStarView{
    UIImage *yellowImage = [UIImage imageNamed:@"yellow"];
    UIImage *grayImage = [UIImage imageNamed:@"gray"];
    
    _gray = [[UIView alloc]initWithFrame:CGRectMake(0, 0, grayImage.size.width*5, grayImage.size.height)];
    _yellow = [[UIView alloc]initWithFrame:CGRectMake(0, 0, yellowImage.size.width*5, yellowImage.size.height)];
    _gray.backgroundColor = [UIColor colorWithPatternImage:grayImage];
    _yellow.backgroundColor = [UIColor colorWithPatternImage:yellowImage];
    
    [self addSubview:_gray];
    [self addSubview:_yellow];
    
    
    float scale = self.frame.size.height/grayImage.size.height;;
    
    _gray.transform = CGAffineTransformMakeScale(scale, scale);
    _yellow.transform = CGAffineTransformMakeScale(scale, scale);

}

- (void)awakeFromNib{
    [self setStarView];
}

- (void)setAverage:(float)average{
    _average = average;
    [self setNeedsLayout];
}


- (void)layoutSubviews{
    
    [super layoutSubviews];
    
    float width = _average/10.0*_gray.frame.size.width;
    CGRect frame = _gray.frame;
    frame.size.width = width;
    _yellow.frame = frame;
}



- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self setStarView];
    }
    return self;
}



@end
